package com.cms.model;

import java.util.Date;

import org.springframework.web.multipart.MultipartFile;

import com.cms.plugin.db.Model;
import com.cms.plugin.db.Page;
import com.cms.plugin.db.annotation.Table;

@Table("s_upload")
public class Uploader extends Model<Uploader>{

	
	public static final Uploader dao = new Uploader();
	/**
	 * 
	 */
	private static final long serialVersionUID = 1672491504604978271L;
	/**
	 * 所有 sql 写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
	 */
	public Page<Uploader> paginate(int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select su.*,suc.chanel_cn_name", "from s_upload su left join s_upload_config suc on suc.id=su.channel order by id desc");
	}
	public boolean addFile(String Filename,String stuff,String randName,String destFilePath,MultipartFile fileData,String remoteIp,String uploadPath,int channel) {
		String sql="insert into s_upload(fileSrcName,fileRandName,fileLinkAttr,fileType,fileSize,uploadIp,channel,uploadDate) values(?,?,?,?,?,?,?,?)";
		Object[] objs=new Object[]{Filename,randName,destFilePath+randName,fileData.getContentType().toString(),fileData.getSize()/1000.0+"KB",remoteIp,channel,new Date()};
		return update(sql, objs);
	}
}
